<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>后台管理 - 易买网</title>
    <link type="text/css" rel="stylesheet" href="../css/style.css"/>
    <script type="text/javascript" src="../scripts/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="../scripts/function-manage.js"></script>
</head>
<body>
<div class="main">
    <h2>分类管理</h2>
    <div class="manage">
        <table class="list" id="tb_category">
            <tr>
                <th>ID</th>
                <th>分类名称</th>
                <th>操作</th>
            </tr>
        </table>
        <table class="list">
            <tr>
                <td align="center">
                    <a href="javascript:void(0)" class="pages" id="firstPage">首页</a>&emsp;
                    <a href="javascript:void(0)" class="pages" id="prevPage">上一页</a>&emsp;
                    <a href="javascript:void(0)" class="pages" id="nextPage">下一页</a>&emsp;
                    <a href="javascript:void(0)" class="pages" id="lastPage">尾页</a>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
</html>
<script>
    var pageIndex;
    var totalPage;

    $(function () {
        var getTopicList = function (curr) {
            $.ajax({
                type: "POST",
                url: "../GetAllCategoryServlet",
                dataType: "JSON",
                data: {
                    keyword: $("#keyword").val(),
                    pageIndex: curr || 1
                },
                success: function (data) {
                    $("#tb_category").find(".append_list").remove();
                    $.each(data.list, function (index, obj) {
                        var className;
                        if (obj.epcid == obj.epcpartentid) {
                            className = "大类&emsp;";
                        } else {
                            className = "&emsp;&emsp;&emsp;&emsp;小类&emsp;";
                        }
                        var $listStr = "<tr class='append_list'><td>" + obj.epcid + "</td>" +
                            "<td>" + className + "" + obj.epcname + "</td>" +
                            "<td><a href='../DelCategoryServlet?epcid=" + obj.epcid + "' onclick='return confirmAct()'>删除</a>&nbsp;" +
                            "<a href='../GetCategoryServlet?epcid=" + obj.epcid + "'>修改</a> &nbsp;</tr>";
                        $("#tb_category").append($listStr);
                    });
                    pageIndex = data.pageIndex;
                    totalPage = data.totalPage;
                }
            });
        }
        getTopicList();

        $(".pages").on("click", function () {
            var pageflag = $(this).attr("id");
            if (pageflag == "firstPage") {
                getTopicList(1);
            } else if (pageflag == "prevPage") {
                pageIndex = pageIndex - 1;
                getTopicList(pageIndex);
            } else if (pageflag == "nextPage") {
                pageIndex = pageIndex + 1;
                if (pageIndex > totalPage) {
                    pageIndex = totalPage;
                }
                getTopicList(pageIndex);
            } else if (pageflag == "lastPage") {
                getTopicList(totalPage);
            }
        });

    });


    function confirmAct() {
        if (confirm('确定要执行此操作吗?')) {
            return true;
        }
        return false;
    }
</script>